﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

namespace NPMonitor.Utility
{
    public class SettingFactory
    {
        static SettingFactory()
        {
            string path = typeof(Setting).Assembly.GetModules()[0].FullyQualifiedName;
            string directory = Path.GetDirectoryName(path);
            string fileFullPath = Path.Combine(directory, "Setting.config");

            XmlSerializer ser = new XmlSerializer(typeof(Setting));
            XmlReader reader = XmlReader.Create(new StreamReader(fileFullPath));
            lock (obj)
            {
                if (instance == null)
                {
                    instance = (Setting)ser.Deserialize(reader);
                }
            }
        }

        private static object obj = new object();
        private static Setting instance;

        public static Setting Create()
        {
            return SettingFactory.instance;
        }
    }
}
